<?php
namespace lib;
/**
 * 上报平台
 * **/
class Request {
    private $client = null;
    private $platformConfig = null;
    public function __construct() {
        $this->platformConfig = Config::$platform;
        $this->client = new \Swoole\Coroutine\Http\Client($this->platformConfig['host'], $this->platformConfig['port']);
        $this->client->setHeaders(['Content-Type' => 'application/json']);
        $this->client->set(['timeout' => 10]);
    }
    
    public function close() {
        $this->client->close();
    }
    
    public function post($url, $data) {
        if(is_array($data)) {
            $data = json_encode($data);
        }
        
        $this->client->post('/' . $this->platformConfig['prefix'] . '/' . $url, $data);
        $body = $this->client->body;
        return $body;
    }
}